package data;

import java.util.*;
import commProtocol.*;


public class HashtableAdapter implements CollectionContactTarget {

	private Hashtable<String, Contact> t;
	
	public HashtableAdapter(){
		t = new Hashtable<String, Contact>();
	}
	
	public  void add(Contact contact){
		t.put(contact.getLogin(), contact);
	}
	
	public void remove(String name){
		try{
			if(t.containsKey(name))
				t.remove(name);
		}
		catch (Exception exp){
			System.out.println("contact inexistant\n");
		}
	}
	
	public void removeAll(){
		t.clear();
	}
	
	public Contact get(String name) {
		Contact c = new Contact("null", "null");

		if(t.containsKey(name))
			c = (Contact) t.get(name);
		else{
			System.out.println("contact inexistant\n");
			c = null;
		}
		return c;
	}
	
	public Iterator<Contact> iterator(){
		return  t.values().iterator();
	}
	
	
}
